package com.meta.context.source.db;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.setting.Setting;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.meta.context.source.IMetaSource;
import com.meta.internal.Options;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class DbSourceImpl implements IMetaSource {
    @Override
    public Map<String, JSONObject> getSources(Options options) {
        try {
            Db.use().findAll("casic_meta");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args) throws SQLException {
        Setting setting = new Setting();
        setting.set("url", "jdbc:mysql://localhost:3306/mate_boot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghai&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true");
        setting.set("username", "root");
        setting.set("password", "123456");
        setting.set("driver", "com.mysql.cj.jdbc.Driver");
        DSFactory dsFactory = DSFactory.create(setting);
        List<Entity> entities = Db.use(dsFactory.getDataSource()).findAll("gen_table");
        JSONArray json = (JSONArray) JSON.toJSON(entities);
        System.out.println(json);


    }
}
